package com.ruoyi.business.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.service.IGwCarService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.entity.GwCar;
import com.ruoyi.common.core.domain.entity.SysUser;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆管理Controller
 *
 * @author ruoyi
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/gw_car")
public class GwCarController extends BaseController
{
    @Autowired
    private IGwCarService gwCarService;

    /**
     * 查询车辆管理列表
     */
    //@PreAuthorize("@ss.hasPermi('gw_car:car:list')")
    @GetMapping("/list")
    public TableDataInfo list(GwCar gwCar)
    {
        startPage();
        List<GwCar> list = gwCarService.selectGwCarList(gwCar);
        return getDataTable(list);
    }

    @GetMapping("/gwCarList")
    public AjaxResult GwCarList(GwCar gwCar)
    {
        gwCar.setUserId( getUserId() );
        //gwCar.setUserId( 1L );
        List<GwCar> list = gwCarService.selectGwCarList(gwCar);
        return AjaxResult.success(list);
    }

    /**
     * 导出车辆管理列表
     */
    //@PreAuthorize("@ss.hasPermi('gw_car:car:export')")
    @Log(title = "车辆管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwCar gwCar)
    {
        List<GwCar> list = gwCarService.selectGwCarList(gwCar);
        ExcelUtil<GwCar> util = new ExcelUtil<GwCar>(GwCar.class);
        util.exportExcel(response, list, "车辆管理数据");
    }

    /**
     * 获取车辆管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('gw_car:car:query')")
    @GetMapping(value = "/{carId}")
    public AjaxResult getInfo(@PathVariable("carId") Long carId)
    {
        return success(gwCarService.selectGwCarByCarId(carId));
    }

    /**
     * 新增车辆管理
     */
    //@PreAuthorize("@ss.hasPermi('gw_car:car:add')")
    @Log(title = "车辆管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GwCar gwCar)
    {
        SysUser user = getLoginUser().getUser();
        gwCar.setUserId(user.getUserId());
        gwCar.setCreateTime( new Date() );
        return toAjax(gwCarService.insertGwCar(gwCar));
    }

    /**
     * 修改车辆管理
     */
    //@PreAuthorize("@ss.hasPermi('gw_car:car:edit')")
    @Log(title = "车辆管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwCar gwCar)
    {
        return toAjax(gwCarService.updateGwCar(gwCar));
    }

    /**
     * 删除车辆管理
     */
    //@PreAuthorize("@ss.hasPermi('gw_car:car:remove')")
    @Log(title = "车辆管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carIds}")
    //@Anonymous
    public AjaxResult remove(@PathVariable Long[] carIds)
    {
        return toAjax(gwCarService.deleteGwCarByCarIds(carIds));
    }
}
